str1 = "Beijing2008OlympicGames"
origin = [1, 2, 3, 4, 5, 6]
key1 = [3, 2, 4, 1, 6, 5]
width = 6
length = len(str1)
height = length // width
if length % width != 0:
    height += 1
key2 = [4, 2, 1, 3, 6, 5]
str1 = "Beijing2008OlympicGames"
def encrypt(str1, key1, height, width):
    M1 = [[" " for j in range(width)] for i in range(height)]
    M2 = [[" " for j in range(width)] for i in range(height)]
    for i in range(0, len(str1)):
        M1[i//width][i%width] = str1[i]
    for i in range(0, len(key1)):
        for j in range(0, height):
            M2[j][key1[i] - 1] = M1[j][origin[i] - 1]
    str2 = ""
    for i in range(0, width):
        for j in range(0, height):
            str2 += str(M2[j][i])
    # return "j0pee2yaBglGi0mmnOc i8is"
    return str2
result1 = encrypt(str1, key1, height, width)
print(result1)